{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import urllib, os\n",
    "\n",
    "#coords = pd.read_csv(\"\")\n",
    "\n",
    "#coords = coords[0:2]\n",
    "#coords.head()\n",
    "#coords.shape\n",
    "\n",
    "API_KEY = 'REPLACE'\n",
    "\n",
    "def join_with_plus(string):\n",
    "    string_list = string.split()\n",
    "    new_string = '+'.join(string_list)\n",
    "    return new_string\n",
    "    \n",
    "def get_google_geo_coding(division, district, school_name, address, API_KEY):\n",
    "    attributes = [division,district,school_name,address] #create list of inputs\n",
    "    attributes = [i.replace(' ', '+') for i in attributes] #make spaces pluses\n",
    "    print(attributes)\n",
    "    base = \"https://maps.googleapis.com/maps/api/geocode/json?address=\"\n",
    "    url = base + attributes[2] + ',' + attributes[3] + '&components=country:PH|locality:' + attributes[0] + '|sublocality' + attributes[1] + '&key=' + API_KEY\n",
    "    #file = \"./clean/AllSubjects/Ensemble2_StaticResNeXt101/data/temp/\" + str(school_id) + \".png\"\n",
    "    print(url)\n",
    "    #return urllib.request.urlretrieve(url)\n",
    "  \n",
    "  \n",
    "count = 1\n",
    "\n",
    "#This was for a spreadhseet with all the school addresses\n",
    "\n",
    "#for index, row in coords.iterrows():\n",
    " #   msg = \"File #\" + str(count)\n",
    "  #  print(msg)\n",
    "   # get_google_geo_coding(row['division'], row['district'], row['school_name'], row['address'], API_KEY)\n",
    "    #count += 1\n",
    "\n",
    "\n",
    "#urllib.request.urlretrieve(\"https://maps.googleapis.com/maps/api/geocode/json?address=Barangay+Upper+Bato-Bato,+Philippines&key=API_KEY\",\n",
    "                          # \"./clean/AllSubjects/Ensemble2_StaticResNeXt101/data/temp/yo.json\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['La+Union', 'Bauang+North', 'EULOGIO+CLARENCE+M.+DE+GUZMAN+Jr.+ELEMENTARY+SCHOOL', 'Pagdalagan+Sur']\n",
      "https://maps.googleapis.com/maps/api/geocode/json?address=EULOGIO+CLARENCE+M.+DE+GUZMAN+Jr.+ELEMENTARY+SCHOOL,Pagdalagan+Sur&components=country:PH|locality:La+Union|sublocalityBauang+North&key=REPLACE\n"
     ]
    }
   ],
   "source": [
    "get_google_geo_coding('La Union','Bauang North','EULOGIO CLARENCE M. DE GUZMAN Jr. ELEMENTARY SCHOOL','Pagdalagan Sur', API_KEY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
